//服务器地址
import {server} from '../config/index.js';

castapp.init();
	
var txtElem = castapp.id('info');
var submitBtn = castapp.id('subm');

//提交
submitBtn.addEventListener('tap',function(e){
	var txtVal = txtElem.value.trim();
	if(!txtVal){
		castapp.prompt('请给出您的宝贵意见');
		return;
	}
	txtVal = txtVal.replace(/[<>]/g,'');
	
	//模拟提交的信息
	castapp.showWaiting('正在提交...');
	var userInfo = localStorage.getItem('userInfo');
	userInfo = userInfo? JSON.parse(userInfo): {};
	castapp.ajax({
		url: server+'/api/user/feedback_suggestion',
		type: 'post',
		data: {
			nickname: userInfo.nickname,
			uuid: userInfo.uuid,
			suggestion: txtVal
		},
		succFn: function(res){
			res = JSON.parse(res);
			castapp.closeWaiting();
			if(res.msg=='OK'){
				castapp.prompt('提交成功，感谢您宝贵意见');
				castapp.closeCurrentInterface(); //关闭当前界面
			}else{
				castapp.prompt('身份验证错误');
			}
		},
		errFn: function(err){
			castapp.closeWaiting();
			castapp.prompt('服务错误，请重试');
		}
	});
});
	